/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package roomarrange;

import com.sun.data.provider.impl.CachedRowSetDataProvider;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import com.sun.webui.jsf.component.Checkbox;
import com.sun.webui.jsf.component.DropDown;
import com.sun.webui.jsf.component.TextArea;
import com.sun.webui.jsf.component.TextField;
import javax.faces.FacesException;
import javax.faces.convert.IntegerConverter;
import javax.faces.event.ValueChangeEvent;
import javax.sql.DataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * <p>Page bean that corresponds to a similarly named JSP page.  This
 * class contains component definitions (and initialization code) for
 * all components that you have defined on this page, as well as
 * lifecycle methods and event handlers where you may add behavior
 * to respond to incoming events.</p>
 *
 * @version vedioTest2.java
 * @version Created on 2009-10-14, 14:27:14
 * @author ben
 */

public class vedioTest2 extends AbstractPageBean {
    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">

    /**
     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */
    private void _init() throws Exception {
        t_roomsetDataProvider.setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.t_roomsetRowSet}"));
    }
    private CachedRowSetDataProvider t_roomsetDataProvider = new CachedRowSetDataProvider();

    public CachedRowSetDataProvider getT_roomsetDataProvider() {
        return t_roomsetDataProvider;
    }

    public void setT_roomsetDataProvider(CachedRowSetDataProvider crsdp) {
        this.t_roomsetDataProvider = crsdp;
    }
    private IntegerConverter dropDown1Converter = new IntegerConverter();

    public IntegerConverter getDropDown1Converter() {
        return dropDown1Converter;
    }

    public void setDropDown1Converter(IntegerConverter ic) {
        this.dropDown1Converter = ic;
    }
    private TextField textField1 = new TextField();

    public TextField getTextField1() {
        return textField1;
    }

    public void setTextField1(TextField tf) {
        this.textField1 = tf;
    }
    private TextField textField2 = new TextField();

    public TextField getTextField2() {
        return textField2;
    }

    public void setTextField2(TextField tf) {
        this.textField2 = tf;
    }
    private DropDown dropDown1 = new DropDown();

    public DropDown getDropDown1() {
        return dropDown1;
    }

    public void setDropDown1(DropDown dd) {
        this.dropDown1 = dd;
    }
    private TextArea textArea1 = new TextArea();

    public TextArea getTextArea1() {
        return textArea1;
    }

    public void setTextArea1(TextArea ta) {
        this.textArea1 = ta;
    }
    private Checkbox checkbox1 = new Checkbox();

    public Checkbox getCheckbox1() {
        return checkbox1;
    }

    public void setCheckbox1(Checkbox c) {
        this.checkbox1 = c;
    }
    private TextArea textArea2 = new TextArea();

    public TextArea getTextArea2() {
        return textArea2;
    }

    public void setTextArea2(TextArea ta) {
        this.textArea2 = ta;
    }

    // </editor-fold>

    /**
     * <p>Construct a new Page bean instance.</p>
     */
    public vedioTest2() {
    }

    /**
     * <p>Callback method that is called whenever a page is navigated to,
     * either directly via a URL, or indirectly via page navigation.
     * Customize this method to acquire resources that will be needed
     * for event handlers and lifecycle methods, whether or not this
     * page is performing post back processing.</p>
     * 
     * <p>Note that, if the current request is a postback, the property
     * values of the components do <strong>not</strong> represent any
     * values submitted with this request.  Instead, they represent the
     * property values that were saved for this view when it was rendered.</p>
     */
    @Override
    public void init() {
        // Perform initializations inherited from our superclass
        super.init();
        // Perform application initialization that must complete
        // *before* managed components are initialized
        // TODO - add your own initialiation code here
        
        // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
        // Initialize automatically managed components
        // *Note* - this logic should NOT be modified
        try {
            _init();
        } catch (Exception e) {
            log("vedioTest2 Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
        }
        
        // </editor-fold>
        // Perform application initialization that must complete
        // *after* managed components are initialized
        // TODO - add your own initialization code here
    }

    /**
     * <p>Callback method that is called after the component tree has been
     * restored, but before any event processing takes place.  This method
     * will <strong>only</strong> be called on a postback request that
     * is processing a form submit.  Customize this method to allocate
     * resources that will be required in your event handlers.</p>
     */
    @Override
    public void preprocess() {
    }

    /**
     * <p>Callback method that is called just before rendering takes place.
     * This method will <strong>only</strong> be called for the page that
     * will actually be rendered (and not, for example, on a page that
     * handled a postback and then navigated to a different page).  Customize
     * this method to allocate resources that will be required for rendering
     * this page.</p>
     */
    @Override
    public void prerender() {
        this.getDropDown1().setSelected(this.getSessionBean1().getIroomid());
    }


    /**
     * <p>Callback method that is called after rendering is completed for
     * this request, if <code>init()</code> was called (regardless of whether
     * or not this was the page that was actually rendered).  Customize this
     * method to release resources acquired in the <code>init()</code>,
     * <code>preprocess()</code>, or <code>prerender()</code> methods (or
     * acquired during execution of an event handler).</p>
     */
    @Override
    public void destroy() {
        t_roomsetDataProvider.close();
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected ApplicationBean1 getApplicationBean1() {
        return (ApplicationBean1) getBean("ApplicationBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected RequestBean1 getRequestBean1() {
        return (RequestBean1) getBean("RequestBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected SessionBean1 getSessionBean1() {
        return (SessionBean1) getBean("SessionBean1");
    }

    public void checkbox1_processValueChange(ValueChangeEvent event) {
        String sMsg="";
        String sDate,eDate;

        String sRoom;
        sRoom = this.getSessionBean1().getSRefMtId();
        sDate = this.getSessionBean1().getSSdate();
        eDate = this.getSessionBean1().getSEdate();
        if(this.getCheckbox1().isChecked()){
            sMsg = "技术科于 "+sDate+"至"+eDate+" 在"+sRoom+" 进行视频会议测试，" +
                    "届时将会断开专网连接，如有不便敬请谅解。";
            this.getTextArea2().setText(sMsg);
        }else{
            //清空断网消息中的内容
            this.getTextArea2().setText(sMsg);
        }

    }

    public String button1_action() {
        // TODO: Process the action. Return value is a navigation
        // case name where null will return to the same page.
        //确认要测试
        int li_host;
        int li_init;
        int li_bj = 0;
        int li_status = 0;
        int li_roomid;
        int li_roomsort;
        int li_usrid=0;
        int li_confirmbygrpid=0;
        int li_netdown=0;
        String sName;
        String sAbstract = null;
        String sNotice = null;
        String sTip = null;
        String sDate = null;
        String eDate = null;
        String sRoomName = null;
        String sRef=null;
        li_roomid = this.getSessionBean1().getIroomid();
        li_host = this.getSessionBean1().getIusrid();
        li_init = 13;//召开部门直接设置为技术科
        sName = "【视频测试】视频会议测试";

        if (this.getTextArea1().getText() == null) {
            info("测试情况不能为空，请填写完整！");
            return null;
        }
        if((Boolean)this.getCheckbox1().getSelectedValue() == true){
            if (this.getTextArea2().getText() == null) {
                info("断网消息不能为空，请填写完整！");
                return null;
            }
            sNotice = this.getTextArea2().getText().toString();
            li_netdown = 1;
        }
        sAbstract = this.getTextArea1().getText().toString();
        sDate = this.getSessionBean1().getSSdate();
        eDate = this.getSessionBean1().getSEdate();
        li_usrid = this.getSessionBean1().getIusrid();
        sRef = this.getSessionBean1().getSRef();


        //更新
        String sMeetingid = this.getSessionBean1().getSUUID();
        //生成临时数据
        ApplicationContext ctx = new ClassPathXmlApplicationContext("SpringConfig.xml");
        DataSource ds = (DataSource) ctx.getBean("dataSourceDBDirect");
        //DataSource ds = (DataSource) ctx.getBean("dataSourcePool");
        DataJdbcDao taskDao = new DataJdbcDao();
        taskDao.setDataSource(ds);
        //取会议室类别
        li_roomsort = taskDao.getRoomSort(li_roomid);
        sRoomName = taskDao.getRoomName(li_roomid);
        li_status = 5;
        sTip = "视频测试已成功申请，请准时在选择会议室进行测试！";
        //将所有的有冲突的会议重新置状态
        taskDao.resolveConflict(sDate, eDate, li_roomid);
        //更新会议数据
        taskDao.updateMeeting(sMeetingid, li_host, li_init, sName, sAbstract, sNotice, li_status,li_usrid,li_roomsort,li_confirmbygrpid,li_netdown);

        //如果需要断网，则向qq发信息
        if (li_netdown==1) {
            //向全体人员发布通知
            int ibj=100;
            meetings mt = new meetings();
            String sapp = this.getSessionBean1().getSApp();
            mt = taskDao.getMeeting(sMeetingid,sapp);
            setupParam stp = new setupParam();
            stp = taskDao.getParam();

            taskDao.sendRTX(mt,ibj,stp);
         }
        //显示提示信息
        this.getSessionBean1().setSTip(sTip);
        //cls
        this.getSessionBean1().setIMtHost(0);
        this.getSessionBean1().setIMtInitdept(0);
        this.getSessionBean1().setIroomid(0);
        this.getSessionBean1().setSEdate("");
        this.getSessionBean1().setSSdate("");
        this.getSessionBean1().setSUUID("");
        this.getSessionBean1().setSMtAbstract("");
        this.getSessionBean1().setSMtName("");
        this.getSessionBean1().setSMtNotice("");
        this.getSessionBean1().setSRefMtId("");

        return "toSucc";

    }
    
}

